function btnadd() {
    window.location.href = "/student/createoredit"
}

function btnback() {
    window.location.href = "/student/index"
}

function btnedit(id) {
    window.location.href = `/student/createoredit/${id}`
}

function btnsave() {
    var stuName = $("[name=name]").val();
    var id = $("[name=id]").val();
    var remarks = $("[name=remarks").val();
    var schoolId = $("[name=schoolId").val();
    var obj = {
        stuName,
        id,
        remarks,
        schoolId
    }

    $.post("/student/save", obj, function () {
        alert("保存成功！")
        window.location.href = "/student/index"
    })
}

function btndel(id) {
    if (confirm("确定删除?")) {
        window.location.href = `/student/delete/${id}`
    }
}

function btnquery() {
    var word = $("[name=keyword]").val();
    var obj = {
        word
    }
    $.post("/student/query", obj, function (res) {
        console.log(res);
        $("[name=tbdata]").html("");
        res.forEach(item => {
            var html = `
                <tr>
                    <td>${item.id}</td>
                    <td>${item.stuName}</td>
                    <td>${item.remarks}</td>
                    <td>
                        <button onclick="btnedit(${item.id})">修改</button>
                        <button onclick="btndel(${item.id})">删除</button>
                    </td>
                </tr>
            `;
            $("[name=tbdata]").append(html);
        });
    })
}